﻿using System;
using RbmlVisualizer.Data.Blocks;

namespace RbmlVisualizer.Logging
{
    public class BlockLoggingService
    {
        private readonly ILoggingService _loggingService;
        private static BlockLoggingService _instance;


        protected BlockLoggingService(ILoggingService loggingService)
        {
            _loggingService = loggingService;
        }

        public static BlockLoggingService Instance { get { return _instance ?? (_instance = new BlockLoggingService(LoggingService.Instance)); } }


        public void LocalConformityStarting(ClassifierBlock rbmlBlock, ClassifierBlock umlBlock)
        {
            _loggingService.WriteInfo("Starting local conformity check of RBML {0} against UML {1}", rbmlBlock, umlBlock);
        }

        public void LocalConformityEnding(ClassifierBlock rbmlBlock, ClassifierBlock umlBlock)
        {
            _loggingService.WriteInfo("Ending local conformity check of RBML {0} against UML {1}", rbmlBlock, umlBlock);
        }

        public void LocalMatchSuccess(ClassifierBlock rbmlBlock, ClassifierBlock umlBlock)
        {
            _loggingService.WriteInfo("Uml block {0} has matched Rbml block {1} in local conformity.", umlBlock, rbmlBlock);
        }

        public void LocalMatchFailed(ClassifierBlock umlBlock)
        {
            _loggingService.WriteInfo("Could not find an Rbml block that {0} conforms to.", umlBlock);
        }

        public void LocalMatchNotFound(ClassifierBlock rbmlBlock)
        {
            _loggingService.WriteError("No local match was found for Rbml block: {0}", rbmlBlock);
        }




        public void GlobalConformityNoMatches(ClassifierBlock rbmlBlock)
        {
            _loggingService.WriteError("Rbml block {0} has no uml blocks globally conforming", rbmlBlock);
        }

        public void GlobalConformityFailed(ClassifierBlock rbmlBlock, ClassifierBlock umlBlock)
        {
            _loggingService.WriteInfo("Global conformity check failed for RBML {0} and UML {1}", rbmlBlock, umlBlock);
        }


        public void TypeMappingRemovedBlock(Tuple<string, string> typeMapping, ClassifierBlock rbmlBlock, ClassifierBlock umlBlock)
        {
            LoggingService.Instance.WriteInfo("Type mapping {0} was found to be invalid so removing mapping from {1} to {2}", typeMapping, rbmlBlock, umlBlock);
        }

        public void TypeMappingIvalidatedBlocks(ClassifierBlock rbmlBlock)
        {
            LoggingService.Instance.WriteError("Type mapping removal caused {0} to have no valid mappings", rbmlBlock);
        }


        public void GlobalMultiplicityFail(ClassifierBlock rbmlBlock, int umlBlocks)
        {
            LoggingService.Instance.WriteError("Global multiplicity for block {0} failed because there was {1} uml blocks mapped", rbmlBlock, umlBlocks);
        }
    }
}
